﻿<!--#include file="../easyasp/easp.asp"-->
<!--#include file="../mae/mae.asp"-->
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>EASP&MAE</title>
</head>
<body style="font-size:12px;padding:0px;margin:0px">
	<div style="padding:10px;">
<%
res.Charset = "utf-8"

'设置数据库连接参数
dim conn : set conn = KeyValue()
conn "DB_Type", "ACCESS"
conn "DB_Path", "./GBqcBsFizy.mdb"
define "MO_DATABASE_DB", conn.valueOf()


'初始化
Mo.Start "../mae/Mo", E_ERROR, E_LOG, E_WARNING, E_MODEL

function EASPMAE()
	'手动连接数据库并托管给Easp.Db
	Model__.connect()
	Easp.Db.DefaultConn = Model__.getConnection()

	'仅仅是测试下，sql语句中的超级变量的表现形式
	Easp.Var("id") = 1
	Easp.Var("name") = "anlige's"
	Easp.Var("memo") = "test"
	F.echo Easp.Db.ToSql("select * from Mo_Public where id={=id} and name={name} and memo={memo}"), true
		
	Easp.Var("memo") = "'test'"
	F.echo Easp.Db.ToSql("select * from Mo_Public where id={=id} and name={name} and memo={=memo}"), true


	'使用Easp查询，并委托给MAE的DataTable
	dim table : set table = DataTable(Easp.Db.Query("select top 2 * from Mo_Public where id<19 order by id desc"))

	'用了MAE中DataTable的遍历方法，必须使用Convert转换VBS方法为JScript方法
	table.each Convert("eachitem")
	F.echo JSON.stringify(table.getArray()), true

	'就是演示下，对VBS来说，这样意义不大，还不如直接调用方法
	dim result :result = F.activex("ADODB.STREAM", Convert("activex"), 3, 2, "哈哈，测试！EASPMAE！")
	F.echo result

end function

function eachitem(item, index)
	'item为一个KeyValue对象，键名为字段名，值为字段值
	dump item
end function

function activex(mode, t, text)
	Me.type = t
	Me.Mode = mode
	Me.Charset = "gb2312"
	Me.Open()
	Me.WriteText text
	Me.Position = 0
	activex = Me.ReadText()
	Me.Close()
end function
	
'必要的清理
Mo.End()
%>
</div>
</body>
</html>